package com.guo.todo.common.util;

import at.favre.lib.crypto.bcrypt.BCrypt;

import java.nio.charset.StandardCharsets;

/**
 * @Auther: hotlove_linx
 * @Date: 2023/7/23 10:32
 * @Description:
 */
public class EncryptUtil {

    /**
     * bcrypt加密算法
     * @param var1 被加密对象
     * @return
     */
    public static String bcryptEncrypt(String var1) {
        return BCrypt.withDefaults().hashToString(12, var1.toCharArray());
    }

    /**
     * bcrypt验证算法
     * @param var1
     * @param var2
     * @return
     */
    public static boolean bcryptVerify(String var1, String var2) {
        BCrypt.Verifyer verifyer = BCrypt.verifyer();
        BCrypt.Result result = verifyer.verify(var1.toCharArray(), var2.toCharArray());
        return result.verified;
    }

    public static void main(String[] args) {
        boolean res = EncryptUtil.bcryptVerify("admin", "$2a$12$qzMBwcGJkpDadMbG5mw9GenHlbCDqaLmIm6MKZdO0gVz.eBm2TAAu");
        System.out.println(res);
    }

    
    
}
